package com.atguigu.juc.study.chapter14.stampedlock;

import java.util.concurrent.TimeUnit;

/**
 *  StampedLock = ReentrantReadWriteLock + 读的过程中也允许获取写锁介入
 *
 * @author : leimingchao
 * @date Date : 2022年06月22日 13:25
 */
public class StampedLockDemo {

    public static void main(String[] args) {

        MyStampedLockResource stampedLockResource = new MyStampedLockResource();

        //传统版------------------------------------------------
        new Thread(() -> {
            stampedLockResource.read();
        }, "readThread").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t" + "come in ");
            stampedLockResource.write();
        }, "writeThread").start();

        //传统版------------------------------------------------
        try {
            TimeUnit.SECONDS.sleep(4);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(Thread.currentThread().getName() + "\t" + "number:" + MyStampedLockResource.number);

    }
}
